import BasePageCtrl, { AnimType } from "./BasePageCtrl";

const { ccclass, property } = cc._decorator;
import n from "./AudioManager"
 import l from "./PeripheralSystemDataMgr"
 import s from "./EventMgr"
 import c from "./MatchGameEventType"
 import u from "./frameworkManager"
 import p from "./AdManager"
 import d from "./SdkHelper"
 import h from "./EngineUtil"
 import f from "./MatchGameData"
 import g from "./MatchGameAudioMgr"
 import y from "./BasePageCtrl"
 import m from "./MatchGameSystemMgr"
 import _, { VideoBuriedPoint } from "./PeripheralSystemMgr"
 import v from "./UiManage"
 import b from "./MatchGameSuccessPage"
import UiManager from "./UiManage";
@ccclass
export default class MatchGameSuccessPageCtrl extends BasePageCtrl {
    canClick: boolean = false;
    step: number = 0;

    public onLoad() {
        this.onUILoad();
        this._animType =  AnimType.NONE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        super.onLoad();
        this.addButtonListen();
    };
    public start() { };
    public onUILoad() {
        this.ui = this.node.addComponent(b);
    };
    public _init(e?) {
        n.getInstance().pauseMusic("bgm", true);
        this.canClick = false;
        this.node.setContentSize(cc.winSize);
        var t = e.strtFlyNode, a = e.step;
        this.step = a;
        this.ui.goldCoinFlySpine.active = false;
        this.ui.sp_title.active = false;
        this.ui.content.active = false;
        this.playFlyAni(t);
        this.step, f.getFlyBoxCash();
        m.matchGameSuccess(this.step, function () {
            d.reportData("matchgame_finish_game_success", {
                level: f.gameLevel,
                game_time: f.getGameTime()
            });
            u.log("通关成功");
        });
        l.setRollingNoticeParent(this.ui.noticeParent);
        s.trigger(c.HIDE_MATCHGAME_NODE);
    };
    public playFlyAni(e) {
        var t = this;
        this.ui.goldCoinFlySpine.active = true;
        this.ui.goldCoinFlySpine.position = cc.v3(h.getNodeAToNodeBPoint(e, this.node));
        var a = this.ui.goldCoinFlySpine.getComponent(sp.Skeleton);
        g.playSuccessPageShowAudio();
        a.setAnimation(0, "idle_2", false);
        a.setAnimation(1, "idle_3", false);
        cc.tween(a.node).delay(.5).to(.6, {
            x: this.ui.sp_title.x,
            y: this.ui.sp_title.y
        }, {
            easing: "backOut"
        }).call(function () {
            a.node.active = false;
            t.ui.sp_title.active = true;
            t.ui.content.active = true;
            t.ui.sp_double_btn.active = false;
            t.ui.sp_title.getComponent(sp.Skeleton).setAnimation(0, "idle_1", false);
            t.ui.sp_title.getComponent(sp.Skeleton).setAnimation(1, "idle_2", true);
            t.canClick = true;
            t.ui.btn_normal.getComponent(cc.Label).string = "只领取" + (t.step / 100).toFixed(2) + "元";
        }).start();
    };
    public addButtonListen() {
        UiManager.addButtonListen(this.ui.btn_double, this.doubleCallback, this);
        UiManager.addButtonListen(this.ui.btn_normal, this.normalCallback, this);
    };
    public doubleCallback() {
        var e = this;
        if (this.canClick) {
            d.reportData("matchgame_click_double_reward", {
                level: f.gameLevel,
                game_time: f.getGameTime()
            });
            l.reportEncourageVideo();
            this.ui.sp_double_btn.getComponent(sp.Skeleton).setAnimation(0, "idle_2", false);
            this.ui.sp_double_btn.getComponent(sp.Skeleton).setAnimation(1, "idle_1", true);
            p.getInstance().playNormalVideoAd(function () {
                var t = l.isArriveNewCity();
                m.successDouble(e.step, t, function () {
                    e.hide();
                    s.trigger(c.END_MATCH_GAME, {
                        is_tg: 1
                    });
                    d.reportData("matchgame_get_double_reward", {
                        level: f.gameLevel,
                        game_time: f.getGameTime()
                    });
                });
            }, function () { });
        }
    };
    public normalCallback() {
        var e = this;
        if (this.canClick) {
            d.reportData("matchgame_click_normal_reward", {
                level: f.gameLevel,
                game_time: f.getGameTime()
            });
            if (f.force_video) {
                l.reportEncourageVideo();
                d.showForceToast("看完广告就能获得大量红包");
                p.getInstance().playNormalVideoAd(function () {
                    l.reportVideoBuriedPoint(VideoBuriedPoint.FORCE_ENCOURAGE);
                    var t = l.isArriveNewCity();
                    m.successDouble(e.step, t, function () {
                        e.hide();
                        s.trigger(c.END_MATCH_GAME, {
                            is_tg: 1
                        });
                    });
                }, function () {
                    e.hide();
                    s.trigger(c.END_MATCH_GAME, {
                        is_tg: 1
                    });
                });
            } else {
                this.hide();
                s.trigger(c.END_MATCH_GAME, {
                    is_tg: 1
                });
            }
        }
    };
    public clickClose() {
        this.hide();
    };
  
    static prefabUrl = "MatchGameSuccessPage";
    static className = "MatchGameSuccessPageCtrl";
}
